package com.nit.lab.mapper.ship;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.nit.lab.dto.ship.ShipTrackDTO;
import com.nit.lab.dto.ship.WorkDTO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

public interface ShipTrackMapper {

    /**
     * @Description: 获取船舶轨迹
     * @Author: zmh
     * @Date: 2021/2/10
     */
    @Select({"<script>SELECT * " +
            "FROM ship_track " +
            "WHERE 1 = 1 " +
            "<if test='mmsiNumber != null'> AND mmsi_number LIKE CONCAT('%', #{mmsiNumber}, '%') </if>" +
            "</script>"})
    List<ShipTrackDTO> query(@Param("mmsiNumber") String mmsiNumber) throws Exception;

    /**
     * @Description: 删除指定船舶轨迹
     * @Author: zmh
     * @Date: 2021/2/10
     */
    @Delete("DELETE from ship_track WHERE mmsi_number = #{mmsiNumber}")
    Integer remove(@Param("mmsiNumber") String mmsiNumber) throws Exception;

    /**
     * @Description: 获取指定船舶轨迹，供查询港口信息使用
     * @Author: zmh
     * @Date: 2021/2/10
     */
    @Select({"<script>SELECT  min(arrive_time) AS `minTime` " +
            "FROM ship_track " +
            "WHERE 1 = 1 " +
            "<if test='mmsiNumber != null'> AND mmsi_number = #{mmsiNumber}</if>" +
            "<if test='portChinese != null'> AND port_chinese = #{portChinese}</if>" +
            "</script>"})
    ShipTrackDTO queryShipMinTime(
            @Param("mmsiNumber") String mmsiNumber,
            @Param("portChinese") String portChinese) throws Exception;

    /**
     * @Description: 获取大于指定日期的船舶信息
     * @Author: zmh
     * @Date: 2021/2/10
     */
    @Select({"<script>SELECT  * " +
            "FROM ship_track " +
            "WHERE 1 = 1 " +
            "<if test='mmsiNumber != null'> AND mmsi_number = #{mmsiNumber} </if>" +
            "<if test='arriveTime != null'> AND arrive_time &gt;= #{arriveTime} </if>" +
            "</script>"})
    List<ShipTrackDTO> queryLaterShip(
            @Param("mmsiNumber") String mmsiNumber,
            @Param("arriveTime") Date arriveTime) throws Exception;



    /**
     * @Description: 获取指定船舶轨迹，判断是否爬虫成功
     * @Author: zmh
     * @Date: 2021/2/22
     */
    @Select({"<script>SELECT * FROM ship_track " +
            "WHERE 1 = 1 " +
            "<if test = 'mmsiNumber != null'> AND mmsi_number = #{mmsiNumber} </if>" +
            "<if test = 'beginTimeStamp != null'> AND begin_time_stamp = #{beginTimeStamp} </if>" +
            "<if test = 'endTimeStamp != null'> AND end_time_stamp = #{endTimeStamp} </if>" +
            "</script>"})
    List<ShipTrackDTO> list4SpecificShip(
            @Param("mmsiNumber")  String mmsiNumber,
            @Param("beginTimeStamp") String beginTimeStamp,
            @Param("endTimeStamp") String endTimeStamp
    ) throws Exception;

}
